package com.tjsinfo.tjsoa.addresslist.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.addresslist.bo.IAddressListAndFilePendingBo;
import com.tjsinfo.tjsoa.addresslist.bo.IAddressListGroupBo;
import com.tjsinfo.tjsoa.addresslist.bo.IAddressListUserBo;
import com.tjsinfo.tjsoa.addresslist.bo.IAddresslistSendBo;
import com.tjsinfo.tjsoa.system.vo.User;

public class ReturnSendAddressListUserAction extends Action{
	private IAddressListUserBo listUserBo;
	private IAddressListGroupBo groupBo;
	private IAddresslistSendBo sendBo;
	private IAddressListAndFilePendingBo addressListAndFilePendingBo;
	/*private ITjsMessageBo tjsMessageBo;
	public ITjsMessageBo getTjsMessageBo() {
		return tjsMessageBo;
	}

	public void setTjsMessageBo(ITjsMessageBo tjsMessageBo) {
		this.tjsMessageBo = tjsMessageBo;
	}*/
	
	public void setAddressListAndFilePendingBo(
			IAddressListAndFilePendingBo addressListAndFilePendingBo) {
		this.addressListAndFilePendingBo = addressListAndFilePendingBo;
	}

	public IAddresslistSendBo getSendBo() {
		return sendBo;
	}

	public void setSendBo(IAddresslistSendBo sendBo) {
		this.sendBo = sendBo;
	}

	public IAddressListUserBo getListUserBo() {
		return listUserBo;
	}

	public void setListUserBo(IAddressListUserBo listUserBo) {
		this.listUserBo = listUserBo;
	}
	public IAddressListGroupBo getGroupBo() {
		return groupBo;
	}

	public void setGroupBo(IAddressListGroupBo groupBo) {
		this.groupBo = groupBo;
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String returnType = request.getParameter("returnType");
		String sendUsersId = request.getParameter("sendUsersId");
		String groupid = request.getParameter("groupid");
		String copyids = request.getParameter("copyids");
		String messageid = request.getParameter("messageid");
		
		addressListAndFilePendingBo.deleteById(messageid);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		sendBo.deleteSendUsers(sendUsersId,user.getUser_id());
		if (returnType.equals("yes")) {
			String[] ids = copyids.split(",");
			for (int i = 0; i < ids.length; i++) {
				listUserBo.CopyListUser(ids[i], groupid);
			}
		}
		
		request.setAttribute("first", "shi");
		request.setAttribute("moduleType", "1");
		//tjsMessageBo.deletetjsmessagebyid(Integer.valueOf(messageid));
		if (user == null) {
			return mapping.findForward("ok");
		}else {
			return mapping.findForward("sessionok");
		}
	}
}
